PropertyCaseDump
A lua script that: *dumps all PropertyCase values out to a file propdump.log *compares PropertyCase values against the existing propdump.log file. Useful to detect which property cases have changed. You can configure a few variables: *Change the range of propcases that is scanned (From propcase and To propcase). *Disable outputting of the file (set ''Do dump? to 0) *Dump to a numbered dump file (set Output to dump# to 1 or more (saves to file propdump.### where ### is the number you choose) *Compare against a numbered dump (set Compare with dump# to 1 or more (compares against file propdump.### where ### is the number you choose) or -1 to disable comparison output. *Do value comparisons in hex (default) or decimal (set As hex? to 0). The most useful thing you may wish to use in other scripts, is that it shows: * how to load a bunch of settings from a file (using LUA's loadstring (see http://www.wowwiki.com/API_loadstring) feature. Maybe see http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4960 or http://ebiff.sourceforge.net/manual.html for more complex examples - hard to find good examples even though this is a common technique in lots of languages e.g. http://json.org/. * how to save data to a file that can be read in again easily (saving state between runs of the script - very useful!). Here is an example of the log file output (which is read in on next script run) for propcases 0 to 10. The file has unneeded whitespace added because I find the extra tabs make the file more readable. Also LUA "arrays" normally have a much cleaner syntax like {itemA, itemB, itemC, itemD}, but I wanted a zero based array and I wanted to easily see the relation between propcase index and the propcase value. { [ 0]= 0, [ 1]= 0, [ 2]= 0, [ 3]= 0, [ 4]= 0, [ 5]= 1, [ 6]= 0, [ 7]= 0, [ 8]= 1, [ 9]= 0, [ 10]= 0, ver=1, from=0, to=20 } The script: --propdump.lua by Morris Johns -- dump property cases and compare for differences against last dump (see http://chdk.wikia.com/wiki/PropertyCase) -- @title propdump @param f From propcase @default f 0 @param t To propcase @default t 279 @param d Do dump? @default d 1 @param h As hex? @default h 1 @param i Compare with dump# @default i 0 @param o Output to dump# @default o 0 -- setup _from = f _to = t _dodump = d _ashex = h if i >= 0 then _compare = true end if i 0 then i = "log" end _infilename = "A/propdump." .. i if o 0 then o = "log" end _outfilename = "A/propdump." .. o function logwrite(...) if _dodump and not outfile then outfile=io.open(_outfilename, "w+b") end if outfile then outfile:write(...) end end function waitshutter() print("press half-shutter") repeat wait_click(100) until not is_pressed("shoot_half") repeat wait_click(100) until is_pressed("shoot_half") end -- load previous data if _compare then infile = io.open(_infilename, "rb") if infile then fn = loadstring("data=" .. infile:read("*a")) if fn then fn() end infile:close() end if not data then print("no existing data") end end -- loop through propcases diffs = {} logwrite("{\n") for i = _from,_to do v = get_prop(i) logwrite("i, "=\t", v, ",\n") if data and data.ver 1 and data.from <= i and i <= data.to then -- do comparison if datai ~= v then if _ashex then num1 = string.sub(string.format('%04X', datai), -4) num2 = string.sub(string.format('%04X', v), -4) else num1 = datai num2 = v end table.insert(diffs, ".. i .. " " .. num1 .. " -> " .. num2) end end end logwrite("ver=1,\n") logwrite("from=", f, ",\n") logwrite("to=", t, ",\n") diffs_were = unpack(diffs) if _compare and diffs_were then logwrite("diffs_were=", string.format("%q", diffs_were), ",\n") end logwrite("}\n") if outfile then outfile:close() end -- tell user the differences if _compare then for i,diff in ipairs(diffs) do print(diff) if i % 4 0 and diffsi+1 then waitshutter() end end if get_mode() 1 then -- in play mode, screen cleared without this waitshutter() end end Category:Scripts Category:Development